﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using Archives.Models.Users;
using System.ComponentModel.DataAnnotations;
using FluentValidation;

namespace Archives.Models.FluentConfiguration
{
    public class UserConfiguration : EntityTypeConfiguration<User>
    {
        public UserConfiguration()
        {
            Property(t => t.Id)
              .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            Property(d => d.FullName).IsRequired();
            Property(d => d.FullName).HasMaxLength(50);

            Property(d => d.Username).IsRequired();
            Property(d => d.Username).HasMaxLength(50);

            Property(d => d.Password).IsRequired();
            Property(d => d.Password).HasMaxLength(50);

            Property(d => d.Email).IsRequired();
            Property(d => d.Email).HasMaxLength(50);
        }
    }

    public class UserValidator : AbstractValidator<User>
    {
        public UserValidator()
        {
            RuleFor(x => x.FullName).NotNull();
            RuleFor(x => x.Username).NotNull();
            RuleFor(x => x.Password).NotNull();
            RuleFor(x => x.Email).NotNull().EmailAddress();
        }
    }
}